package com.threeonemeeting.activity;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.threeonemeeting.R;
import com.threeonemeeting.model.MeetingCommentInfo;
import com.threeonemeeting.model.MeetingCommentListItemInfo;
import com.threeonemeeting.tab.BaseTabActivity;
import com.threeonemeeting.util.MiscUtil;

public class MeetingCommentDetailActivity extends BaseTabActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ac_meeting_comment_detail);
		MiscUtil.setBackBtnListener(this);

		final MeetingCommentInfo mInfo = (MeetingCommentInfo) getIntent()
				.getExtras().getSerializable("comment");
		if (mInfo == null) {
			return;
		}

		final MeetingCommentInfo repliedInfo = (MeetingCommentInfo) getIntent()
				.getExtras().getSerializable("rcomment");

		LinearLayout replyLayout = (LinearLayout) findViewById(R.id.reply_layout);
		LinearLayout replyImageLayout = (LinearLayout) findViewById(R.id.refimage_layout);
		replyLayout.setVisibility(View.GONE);
		replyImageLayout.setVisibility(View.GONE);

		MeetingCommentListItemInfo lvInfo = new MeetingCommentListItemInfo();
		lvInfo.nCommentUserId = mInfo.nCommentUserId;
		lvInfo.nMeetingId = mInfo.nMeetingId;
		lvInfo.nCommentId = mInfo.nCommentId;
		lvInfo.nReplyNum = mInfo.nReplyNum;
		lvInfo.strCommentName = mInfo.strCommentName;
		lvInfo.strCommentTime = mInfo.strCommentTime;
		lvInfo.strCommentText = mInfo.strCommentText;
		lvInfo.bIsHaveImage = mInfo.bIsHaveImage;
		lvInfo.bReplied = mInfo.bReplied;

		if (repliedInfo != null) {
			lvInfo.strRepliedCommentName = repliedInfo.strCommentName;
			lvInfo.strRepliedCommentText = repliedInfo.strCommentText;
			lvInfo.strRepliedCommentTime = repliedInfo.strRepliedCommentTime;
		}

		// 设置头像
		String strImageUrl = "http://file.31huiyi.com/UserFaceHandler.ashx?uid="
				+ lvInfo.nCommentUserId;
		ImageView headerImage = (ImageView) findViewById(R.id.comment_header);
		MiscUtil.setImageView(headerImage, strImageUrl);

		// 设置评论者的姓名
		TextView commentNameTextView = (TextView) findViewById(R.id.comment_name);
		commentNameTextView.setText(lvInfo.strCommentName);

		// 评论的内容
		TextView commentContentTextView = (TextView) findViewById(R.id.comment_text);
		commentContentTextView.setText(lvInfo.strCommentText);

		// 被评论的内容
		if (mInfo.bReplied == true) {
			replyLayout.setVisibility(View.VISIBLE);

			TextView repliedCommentNameTextView = (TextView) findViewById(R.id.replied_comment_name);
			repliedCommentNameTextView.setText(lvInfo.strRepliedCommentName);

			TextView repliedCommentTimeTextView = (TextView) findViewById(R.id.replied_comment_time);
			repliedCommentTimeTextView.setText(lvInfo.strRepliedCommentTime);

			TextView repliedCommentContentTextView = (TextView) findViewById(R.id.replied_comment_text);
			repliedCommentContentTextView.setText(lvInfo.strRepliedCommentText);

		}

		if (mInfo.bIsHaveImage == true) {
			ImageView refImage = (ImageView) findViewById(R.id.comment_ref_image);
			MiscUtil.setImageView(refImage, mInfo.strImageUrl);
			replyImageLayout.setVisibility(View.VISIBLE);
		}

		// 添加评论的按钮
		Button btnReplyComment = (Button) findViewById(R.id.btn_replycomment);
		btnReplyComment.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Bundle b = new Bundle();
				b.putInt("eid", mInfo.nMeetingId);
				b.putInt("tid", mInfo.nCommentId);
				startActivity("SendCommentActivity", b);
			}
		});
	}
}
